package y25.m2;

import java.util.HashMap;
import java.util.Map;

public class leetcode_238 {
    class Solution {
//        public int[] productExceptSelf(int[] nums) {
////            int[] answer = new int[nums.length];
////            int[] zero = get(nums);
////            if (zero[0] == 1) {
////                answer[zero[1]] = m(nums, zero[1], zero);
////                for (int j = 0; j < nums.length; j++) {
////                    if (j != zero[1]) {
////                        answer[j] = 0;
////                    }
////                }
////                return answer;
////            } else if (zero[0] > 1) {
////                for (int j = 0; j < nums.length; j++) {
////                    answer[j] = 0;
////                }
////                return answer;
////            }
////            Map<Integer, Integer> mMap = new HashMap<>();
////            for (int i = 0; i < nums.length; i++) {
////                if (mMap.get(nums[i])!= null) {
////                    answer[i] = mMap.get(nums[i]);
////                }else{
////                    answer[i] = m(nums, i, zero);
////                    mMap.put(nums[i], answer[i]);
////                }
////
////            }
////            return answer;
//        }

        public int m(int[] nums, int p, int[] zero) {
            int s = 1;
            for (int j = 0; j < nums.length; j++) {
                if(j != p){
                    s *= nums[j];
                }
                if (nums[j] == 0){
                    zero[0]++;
                    zero[1] = j;
                    if(zero[0] > 1){
                        return 0;
                    }
                }
            }
            return s;
        }
    }
    public static void main(String[] args) {
        Solution solution = new leetcode_238().new Solution();
//        System.out.println(solution.productExceptSelf(new int[]{-1,1,0,-3,3}));

    }
}
